package com.qunar.wan.util;

import com.google.common.base.Preconditions;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * User: cyoung Date: 11/28/13 Time: 4:33 PM
 */
public class DateUtil {
    private DateUtil() {
    }

    public static String getHHMM(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        return sdf.format(date);
    }

    public static String getDay(Date date) {
        Preconditions.checkArgument(date != null, "param date can not be null");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    public static String parse2ymdhms(Date date) {
        Preconditions.checkArgument(date != null, "param date can not be null");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    public static Date combine2Date(String yyyyMMdd, String HHmmss) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return sdf.parse(new StringBuilder(yyyyMMdd).append(" ").append(HHmmss).toString());
    }

}
